Add a private function for accessible factory registration
authorMatthias Clasen <mclasen@redhat.com>
Thu, 17 Feb 2011 06:24:43 +0000 (01:24 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 17 Feb 2011 06:24:43 +0000 (01:24 -0500)
This avoids repeating the same code for each widget that
has its own accessible implementation inside GTK+.

gtk/Makefile.am
gtk/gtkaccessible.c
gtk/gtkaccessibleprivate.h [new file with mode: 0644]

index c95adb7323d2d3a31529b2773f690812b473134f..35692629232509b1399c963d1a8a4911d65c5a11 100644 (file)
@@ -376,6 +376,7 @@ endif
 gtk_private_h_sources =                \
        gtk9slice.h             \
        gtkaccelgroupprivate.h  \
+       gtkaccessibleprivate.h  \
        gtkanimationdescription.h \
        gtkappchooserprivate.h  \
        gtkappchoosermodule.h   \
index 532f476e7f9a138d91bf9b5f467d48b15f2f66f2..81e0fec2b66f70b7ece6758bf801c492e22ec652 100644 (file)
@@ -131,3 +131,34 @@ gtk_accessible_real_connect_widget_destroyed (GtkAccessible *accessible)
                       &priv->widget);
   }
 }
+
+/*
+ * _gtk_accessible_set_factory_type:
+ * @widget_type: a #GtkWidget subtype
+ * @factory_type: a #AtkObjectFactory subtype
+ *
+ * A wrapper around atk_registry_set_factory_type().
+ *
+ * Only installs the factory if accessibility is
+ * enabled.
+ */
+void
+_gtk_accessible_set_factory_type (GType widget_type,
+                                  GType factory_type)
+{
+  AtkObjectFactory *factory;
+  AtkRegistry *registry;
+  GType accessible_type;
+
+  /*
+   * Figure out whether accessibility is enabled by looking
+   * at the type of the accessible object which would be created
+   * for GtkWidget.
+   */
+  registry = atk_get_default_registry ();
+  factory = atk_registry_get_factory (registry, GTK_TYPE_WIDGET);
+  accessible_type = atk_object_factory_get_accessible_type (factory);
+  if (g_type_is_a (accessible_type, GTK_TYPE_ACCESSIBLE))
+    atk_registry_set_factory_type (registry, widget_type, factory_type);
+}
+
diff --git a/gtk/gtkaccessibleprivate.h b/gtk/gtkaccessibleprivate.h
new file mode 100644 (file)
index 0000000..6bf5a50
--- /dev/null
@@ -0,0 +1,31 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __GTK_ACCESSIBLE_PRIVATE_H__
+#define __GTK_ACCESSIBLE_PRIVATE_H__
+
+#include "gtkaccessible.h"
+
+G_BEGIN_DECLS
+
+void     _gtk_accessible_set_factory_type (GType widget_type,
+                                           GType factory_type);
+
+G_END_DECLS
+
+#endif  /* __GTK_ACCESSIBLE_PRIVATE_H__ */